// Option.cpp : implementation file
//

#include "stdafx.h"
#include "CStudyChinese.h"
#include "Option.h"
#include "dicmanager.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COption dialog
#include "..\dicmodule.h"

COption::COption(CWnd* pParent /*=NULL*/)
	: CTabDlg(COption::IDD, pParent)
{
	//{{AFX_DATA_INIT(COption)
	m_bAllowGetWord = FALSE;
	m_bAllowInMain = FALSE;
	m_bByChar = FALSE;
	m_bByWord = FALSE;
	//}}AFX_DATA_INIT
	bcolor=RGB(0,0,0);
	fcolor=RGB(0,0,0);
}	


void COption::DoDataExchange(CDataExchange* pDX)
{
	CTabDlg::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COption)
	DDX_Control(pDX, IDC_CB_BACK, m_cbBack);
	DDX_Control(pDX, IDC_CB_FRONT, m_cbFront);
	DDX_Check(pDX, IDC_CHK_ALLOWGETWORD, m_bAllowGetWord);
	DDX_Check(pDX, IDC_CHK_ALLOWINMAIN, m_bAllowInMain);
	DDX_Check(pDX, IDC_CK_BYCHAR, m_bByChar);
	DDX_Check(pDX, IDC_CK_BYWORD, m_bByWord);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COption, CTabDlg)
	//{{AFX_MSG_MAP(COption)
	ON_BN_CLICKED(IDC_CK_BYCHAR, OnCkBychar)
	ON_BN_CLICKED(IDC_CK_BYWORD, OnCkByword)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COption message handlers


BOOL COption::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
    m_cbBack.InitializeDefaultColors();
	m_cbFront.InitializeDefaultColors();
	m_cbBack.SetSelectedColorValue(CAppSetting::Instance()->m_BkColor);
	m_cbFront.SetSelectedColorValue(CAppSetting::Instance()->m_FrontColor);

    m_bAllowGetWord = CAppSetting::Instance()->m_bAllowGetWord ;
	m_bAllowInMain = CAppSetting::Instance()->m_bAllowInMain ;
    
	if(CAppSetting::Instance()->m_nGetWordType == TYPE_CHAR)
	{
		m_bByChar = TRUE ;
		m_bByWord = FALSE ;
	}
	else
	{
		m_bByChar = FALSE ;
		m_bByWord = TRUE ;
	}

	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void COption::SaveUpdateSetting()
{
	this->UpdateData();
	CAppSetting::Instance()->m_bAllowGetWord = this->m_bAllowGetWord ;
	CAppSetting::Instance()->SetAppIcon();

	CAppSetting::Instance()->m_bAllowInMain = this->m_bAllowInMain ;
	CAppSetting::Instance()->m_BkColor = m_cbBack.GetSelectedColorValue() ;
	CAppSetting::Instance()->m_FrontColor = m_cbFront.GetSelectedColorValue();

	if(m_bByChar)
	{
        CAppSetting::Instance()->m_nGetWordType = TYPE_CHAR;
	    CDicManager::Instance()->SetGetWordType(TYPE_CHAR);
	}
	else
	{
        CAppSetting::Instance()->m_nGetWordType = TYPE_WORD;
	    CDicManager::Instance()->SetGetWordType(TYPE_WORD);
	}

}



void COption::OnCkBychar() 
{
	UpdateData();
	m_bByWord = !this->m_bByChar ;
	UpdateData(FALSE);
}

void COption::OnCkByword() 
{
	UpdateData();
	m_bByChar = !this->m_bByWord ;
	UpdateData(FALSE);	
}
